package Concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Description：
 * Author: zhangc
 * Date：2017/10/5 20:35
 */
public class ScheduledThreadPoolExecutorTest {

    private static ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(5);
    private static AtomicInteger integer = new AtomicInteger(0);

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++)
            scheduled.scheduleAtFixedRate(new MyTimer(integer.getAndIncrement() + " "), 0, 3, TimeUnit.SECONDS);
    }

    static class MyTimer implements Runnable {
        private String name;

        public MyTimer(String name) {
            this.name = name;
        }

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " : " + System.currentTimeMillis());
        }
    }

}
